package com.edushare.common.vo;

import com.edushare.common.vo.FileDirectories.DIRECTORY_OWNER_TYPE;
import com.edushare.common.vo.auto._CourseInstances;
import com.edushare.common.vo.interfaces.IFileUploadable;

public class CourseInstances extends _CourseInstances implements
		EduShareEntity, IFileUploadable, NameComparision {
	private static final long serialVersionUID = 1304463390887180491L;
	public static final int COURSE_OPEN_LINKED_TO_BATCH = 10;
	public static final int COURSE_OPEN_STANDALONE = 20;
	public static final int COURSE_CLOSED = 30;
	public static final int COURSE_CLOSED_ADMINISTRATIVE = 40;

	public CourseInstances() {
		setSettings("zms:qd;zmv:qd;zcv:qd;zcc:qc;");
	}

	public int getObjectPrimaryKey() {
		return getCourseInstanceId();
	}

	public DIRECTORY_OWNER_TYPE getObjectType() {
		return FileDirectories.DIRECTORY_OWNER_TYPE.COURSE_INSTANCE;
	}

	public String getUploadedFileUrl() {
		return getCourse().getUploadedFileUrl();
	}

	public String getTitle() {
		return getCourse().getCourseName();
	}

	public String getName() {
		return getTitle() + ", " + getSemester().getSemesterName() + " "
				+ getInstanceYear();
	}

	public int compareTo(INameComparable o) {
		return getName().compareTo(o.getName());
	}
	
	public boolean isActive(){
		return getStatus() == COURSE_OPEN_LINKED_TO_BATCH ||
			getStatus() == COURSE_OPEN_STANDALONE;
	}
	
	@Override
	public void setCourse(Courses course) {
		super.setCourse(course);
		setInstanceCredits(course.getCredits());
    }
	
	@Override
	public Integer getInstanceCredits(){
		Integer credits = super.getInstanceCredits();
		if(credits == null){
			credits = getCourse().getCredits();
			setInstanceCredits(credits);
		}
		return credits;
	}
	
}
